<!-- 使用步骤：
  1、先设置
    this.loadingTime = 60
    this.isLoading = true
  2、再调用 loading 方法
  3、在流程之后，还原状态
    再次调用 this.loading()
-->

<template>
  <div class="mint-indicator">
    <div class="mint-indicator-wrapper">
      <span class="mint-indicator-spin">
        <div class="mint-spinner-snake"></div>
      </span>
      <span class="mint-indicator-text">{{showLoadingText}}</span>
    </div>
    <div class="mint-indicator-mask"></div>
  </div>
</template>

<script>
export default {
  props: ['loadingText'],
  data () {
    return {
      loadingTime: 60, // 默认是60秒
      isLoading: false,
      showLoadingText: this.loadingText || '加载中...'
    }
  },
  methods: {
    loading () {
      if (this.loadingTime === 0) {
        this.isLoading = false
      } else {
        this.loadingTime--
        setTimeout(() => {
          this.startLoading()
        }, 1000)
      }
      console.log('this.loadingTime', this.loadingTime)
    }
  }
}
</script>

<style lang="less" scoped>
.mint-indicator {
  .mint-indicator-wrapper {
    padding: 20px;
    top: 50%;
    left: 50%;
    position: fixed;
    -webkit-transform: translate(-50%,-50%);
    transform: translate(-50%,-50%);
    border-radius: 5px;
    background: rgba(0,0,0,.7);
    color: #fff;
    box-sizing: border-box;
    text-align: center;
    z-index: 2;
  }
  .mint-indicator-spin {
    display: inline-block;
    text-align: center;
  }
  .mint-spinner-snake {
    -webkit-animation: mint-spinner-rotate .8s infinite linear;
    animation: mint-spinner-rotate .8s infinite linear;
    border: 4px solid transparent;
    border-radius: 50%;
    border-top-color: rgb(204, 204, 204);
    border-left-color: rgb(204, 204, 204);
    border-bottom-color: rgb(204, 204, 204);
    height: 32px;
    width: 32px;
  }
  .mint-indicator-text {
    display: block;
    color: #fff;
    text-align: center;
    margin-top: 10px;
    font-size: 16px;
  }
  .mint-indicator-mask {
    top: 0;
    left: 0;
    position: fixed;
    width: 100%;
    height: 100%;
    opacity: 0.4;
    background: #000;
    z-index: 1;
  }
}

@keyframes mint-spinner-rotate {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}
</style>
